home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / MA3.1.1 & CW4.5 / Modifications / Use these Mods
Encoding:
Text File  |  1994-09-30  |  9.9 KB  |  387 lines  |  [TEXT/MMCC]

  1. MacApp 3.1.1 mods for CW4.5
  2. Mark Anderson
  3. metrowerks
  4. 9/13/94
  5.  
  6. •••Do not use these mods with versions of CW earlier than CW1.1.1.
  7. •••Scriptable Text Editor is necessary for the debug versions.  STE is a part of 
  8. AppleScript which is found on the CW4 CD.
  9.  
  10. This file has the specific changes necessary for MacApp 3.1.1.  If you would prefer
  11. to simplify the process, the folder "*OR* replace these files" has the complete 
  12. files you need to change.
  13.  
  14. In UMenuMgr.cp
  15.  
  16. •••change IsSetupMenu to 
  17.  
  18. Boolean IsSetupMenu(MenuHandle aMenuHandle,
  19.                     Boolean isHierarchical)
  20.  
  21. {
  22.     if (!IsHandle((Handle) aMenuHandle))
  23.     {
  24. #if qDebug
  25.         VerboseIsHandle((Handle) aMenuHandle);
  26.         ProgramBreak("In IsSetupMenu: not handed a handle.");
  27. #endif
  28.         return false;
  29.     }
  30.     
  31.     MenuID menuID = (*aMenuHandle)->menuID;
  32.     
  33.     if (menuID == mApple) return false;                        // _NEVER_ managed! 
  34.  
  35. #if qDebug
  36.     if (menuID == mDebug) return true;
  37. #endif
  38.  
  39.     if (isHierarchical)
  40.     {
  41.         if ((menuID < kHierarchicalMin) || (menuID > kHierarchicalMax))
  42.             return false;    // must be in valid range for hierarchicals
  43.     }
  44.     return ((menuID >= mFirstMenu) && (menuID <= mLastMenu));    // Range of managed menus
  45.     
  46. } // IsSetupMenu 
  47.  
  48. •••••••••••••••••••••
  49. In UMenuMgr.cp
  50.  
  51. (In previous versions of my mods, I had you change EndMenuSetup.  Please change
  52. it back to the original.  The mod for IsSetupMenu makes this one unnecessary.)
  53. •••change EndMenuSetup to the original version which is
  54.  
  55. void EndMenuSetup(MenuHandle aMenuHandle,
  56.                   Boolean isHierarchical,
  57.                   void* staticLink)
  58.  
  59. {
  60.     long newFlags;
  61.  
  62.     if (IsSetupMenu(aMenuHandle, isHierarchical))
  63.     {
  64.         newFlags = (*aMenuHandle)->enableFlags;
  65.         // If any items are enabled, enable the menu 
  66.         if (newFlags != 0)
  67.         {
  68.             newFlags = (1 | newFlags);
  69.             (*aMenuHandle)->enableFlags = newFlags;
  70.         }
  71.  
  72.         // If the menu's enabled state changed, we have to draw the menu bar. 
  73.         if (((newFlags & 1) == 1) != ((SetupStructPtr)staticLink)->wasEnabled[(*aMenuHandle)->menuID])
  74.             InvalidateMenuBar();
  75.  
  76.         // Restore the menuproc. 
  77.         (*aMenuHandle)->menuProc = ((SetupStructPtr)staticLink)->savedProcs[(*aMenuHandle)->menuID];
  78.         
  79.         // menuWidth set to 0 by routines that require CalcMenuSize, by
  80.         // calling NeedCalcMenu.
  81.         if (!(*aMenuHandle)->menuWidth)
  82.             CalcMenuSize(aMenuHandle);
  83.     }
  84. } // EndMenuSetup 
  85.  
  86. •••••••••••••••••••
  87. In UMacAppGlobals.cp
  88.  
  89. •••Change original to
  90. void InitUMacApp_Step3(short callsToMoreMasters)
  91. {
  92.     // Install MacApp's Memory management system 
  93.     InitUMemory(callsToMoreMasters);
  94.  
  95. #if !qPowerPC
  96.     UnloadAllSegments();
  97.     
  98.     // Force the init segment to be memory resident, so we can call UnloadAllSegs
  99.     // during init
  100.     short initSeg = GetSegNumber((ProcPtr) & DoInitUMacApp);
  101. #ifdef __MWERKS__
  102. //CW can't set up the jump table if if it has already been set up.  If it's locked 
  103. //then it's set up.
  104. {
  105.     Handle seg;
  106.     Handle GetSegResource(short segnum);
  107.     
  108.     seg = GetSegResource(initSeg);
  109.     if (IsHandleLocked(seg))                // not yet locked 
  110.         (*gIsResidentSeg)[initSeg - 1] = true;
  111.     else
  112.         SetResidentSegment(initSeg, true);
  113.     
  114. }    
  115. #else
  116.     SetResidentSegment(initSeg, true);
  117. #endif
  118. #endif
  119.  
  120.     DoInitUMacApp();                        // do rest of initialization 
  121.  
  122. #if !qPowerPC
  123.     SetResidentSegment(initSeg, false);        // make it non-resident 
  124.     UnloadAllSegments();
  125. #endif
  126. } // InitUMacApp_Step3 
  127.  
  128. •••••••••••••••••••
  129. In UMacAppUtilities.h
  130.  
  131. •••Change original to
  132.  
  133. #if qDebug
  134. #ifdef __MWERKS__
  135.     #pragma pointers_in_D0
  136. #endif
  137. Ptr GetCurStackFramePtr() = { 0x200E };            // MOVE.L A6,D0
  138.                                                 // Return the value of register A6.
  139.                                                 // Usually a pointer to the local
  140.                                                 // stack frame.  Most often used to
  141.                                                 // find out the caller's name when
  142.                                                 // invoking a debugging routine.
  143.     
  144. Ptr GetCurStackTop() = { 0x200F };                // MOVE.L A7,D0
  145.                                                 // Return the value of register A7.
  146.                                                 // Usually the top of the stack.
  147.                                                 // Useful for stack sniffing (not
  148.                                                 // a crime).
  149. #ifdef __MWERKS__
  150.     #pragma pointers_in_A0
  151. #endif
  152. #endif
  153. •••••••••••••••••••
  154. In UMemory.cp
  155. In DoInitUMemory change original to
  156.  
  157.     SetResLoad(oldResLoad);
  158.     //###########################################
  159.  
  160.     mainSegment = GetSegNumber((ProcPtr) & InitUMemory);// Main is always resident 
  161.     (*gIsResidentSeg)[mainSegment - 1] = true;
  162.  
  163.     utilitySegment = GetSegNumber((ProcPtr) & UnloadAllSegments);// Utilities are always resident 
  164.     (*gIsResidentSeg)[utilitySegment - 1] = true;
  165.  
  166. #ifdef __MWERKS__ // __%Main must be resident
  167.     (*gIsResidentSeg)[0] = true;
  168. #endif    
  169.  
  170. #if qModelFarCode
  171.  
  172. •••••••••••••••••••
  173. In UMemory.cp
  174.  
  175. •••Change original to 
  176.  
  177. short GetSegNumber(ProcPtr aProc)
  178. {
  179.     static const short kLoaded = 0x4EF9;        // if loaded then a JMP instruction
  180. #ifdef __MWERKS__
  181.     static const short kUnLoaded = 0xA9F0;        // if loaded then a JMP instruction
  182.     const    short    offset = 6;
  183. #else
  184.     static const short kUnLoaded = 0x3F3C;        // if unloaded then a Move instruction (seg# onto stack)
  185.     const    short    offset = 2;
  186. #endif
  187.  
  188.     if (*((const short *)aProc) == kLoaded)        // loaded segment 
  189. #ifdef __MWERKS__
  190.         return *((const short *)((const char *) aProc + offset));
  191. #else
  192.         return *((const short *)((const char *) aProc - offset));
  193. #endif
  194.     else if (*((const short *)aProc) == kUnLoaded)    // unloaded segment 
  195.         return *((const short *)((const char *) aProc + offset));
  196.     else                                        /* routine that computed &proc was in same
  197.                                                   segment as the proc */
  198.     {
  199. #if qDebug
  200.         ProgramBreak("GetSegNumber was not passed an jump table address");
  201. #endif
  202.  
  203.         return 0;
  204.     }
  205. } // GetSegNumber 
  206. •••••••••••••••••••
  207. In UMemory.cp
  208.  
  209. •••Change original to
  210.  
  211. void LoadResidentSegments()
  212. {
  213.     short offset, 
  214.     segnum, 
  215.     rsrcCnt;
  216.     Handle nameList,  seg;
  217.     SignedBytePtr p;
  218.     CStr255 name;
  219.     ResType theType;
  220.     char savedState;
  221.  
  222.     rsrcCnt = CountResources('res!');
  223.     for (short resIndex = 1; resIndex <= rsrcCnt; ++resIndex)
  224.     {
  225.         nameList = GetIndResource('res!', resIndex);
  226.         savedState = HGetState(nameList);
  227.         HNoPurge(nameList);
  228.  
  229.         offset = 2;
  230.         short numNames = *((IntegerPtr) * nameList);
  231.         for (short i = 1; i <= numNames; ++i)
  232.         {
  233.             p = (SignedBytePtr)(*nameList + offset);
  234.             BlockMove(p, &name, *p + 1);
  235.             offset += name.Length() + 1;
  236.  
  237.             seg = MAGet1NamedResource(kCode, name);
  238.  
  239.             if (seg)
  240.             {
  241.                 GetResInfo(seg, &segnum, &theType, name);
  242. #ifdef __MWERKS__
  243.                 if (IsHandleLocked(seg))    // if its locked, then jump table is already set up
  244.                     (*gIsResidentSeg)[segnum - 1] = true;
  245.                 else                
  246. #endif
  247.                     SetResidentSegment(segnum, true);
  248.             }
  249.         }
  250.  
  251.         HSetState(nameList, savedState);
  252.         ReleaseResource(nameList);
  253.     }
  254. } // LoadResidentSegments 
  255.  
  256. •••••••••••••••••••
  257. In UMemory.cp
  258.  
  259. •••Just before DoUnloadAllSegments change original to
  260.  
  261. typedef ModelFarCodeHeader *ModelFarCodeHeaderPtr,
  262.  **ModelFarCodeHeaderHandle;
  263. #ifdef __MWERKS__
  264. const short kJTSkipOver = 4; //for large model, CW looks at the 2nd long in the resource 
  265. #else
  266. const short kJTSkipOver = 2;                    // size of jmp (or loadseg) instruction
  267.                                                 // that must be skipped in the JT Entry in
  268.                                                 // order to get to the target address
  269. #endif
  270. #endif
  271.  
  272. •••••••••••••••••••
  273. In UMemory.cp
  274.  
  275. •••Change original to
  276.  
  277. void DoUnloadAllSegments(void* scopeLink)
  278. {
  279.     long* jmpTablePtr = (long*)scopeLink;
  280.     short i;
  281.     Handle seg;
  282.     for (i = 0; i < pMaxSegNum; ++i)
  283.     {
  284.         if (!(*gIsResidentSeg)[i] && (*gIsLoadedSeg)[i])
  285.         {
  286.             seg = (*gCodeSegs)[i];
  287.             if ((seg) && !IsHandlePurged(seg))
  288.             {
  289.                 if (IsModelFarCodeSegment(seg))
  290.                 {
  291.                     if ((*((ModelFarCodeHeaderHandle)seg))->numOf16BitEntries)
  292.                         UnloadSeg((Ptr)(*jmpTablePtr + (*((ModelFarCodeHeaderHandle) seg))->
  293.                                         A5OffsetOf16BitEntries + kJTSkipOver));
  294.                     else                            // Has to be the other since we wouldn't even
  295.                         // have a segment otherwise
  296.                         UnloadSeg((Ptr)(*jmpTablePtr + (*((ModelFarCodeHeaderHandle)seg))->
  297.                                         A5OffsetOf32BitEntries + kJTSkipOver));
  298.                 }
  299.                 else
  300.                 {
  301. #ifdef __MWERKS__
  302.                     long firstProcInSegment = (*(long*)((*seg) + kJTSkipOver)) + (long) GetA5();
  303.                     UnloadSeg((Ptr)firstProcInSegment);
  304.  
  305. #else
  306.                     UnloadSeg((Ptr)(*jmpTablePtr + **((IntegerHandle)seg) + kJTSkipOver));
  307. #endif
  308.  
  309.                 }
  310.                 HNoPurge(seg);
  311.                 (*gIsLoadedSeg)[i] = false;
  312.             }
  313.         }
  314.     }
  315. } // DoUnloadAllSegments 
  316.  
  317. •••••••••••••••••••
  318. In UObject.h
  319.  
  320. •••Change original to
  321.  
  322. //----------------------------------------------------------------------------------------
  323. // TObject: Definition of the system's root object
  324. //----------------------------------------------------------------------------------------
  325.  
  326. DeclareClassDesc(TObject);
  327.  
  328. // ••• JS NEW ••• singleobject + forceclassidfirst + classdescmany
  329.  
  330. #if qMultipleInheritance || qPowerPC || defined(__MWERKS__) || defined(THINK_C) || defined(__SC__)
  331.     #if (qDebug || qSym) && defined(__MWERKS__)
  332.         // make sure CodeWarrior puts fClassID first, not the vtable
  333.         struct ForceClassIDFirst
  334.         {
  335.            ClassID fClassID;
  336.         };
  337.         class TObject : public ForceClassIDFirst
  338.     #else
  339.         // assume the other compilers already put fClassID first (for Jasik)
  340.         class TObject
  341.     #endif
  342. #else
  343.     // for MPW C only and no MI, descend from SingleObject, so vtables are smaller
  344.     class TObject : public SingleObject
  345. #endif
  346. {
  347.     DeclareClass(TObject);
  348.     
  349. public:
  350.  
  351. #if (qDebug || qSym) && !defined(__MWERKS__)
  352.     ClassID fClassID;                // Used to do object validation in debug mode.
  353. #endif
  354.  
  355. •••••••••••••••••••
  356. In UApplication.cp 
  357.  
  358. •••Change the end of TApplication::DoMenuCommand to
  359.  
  360.         case cPerfMonEnd:
  361.             {
  362.                 TerminatePerfMonitor();
  363. //MW I added this break; was there a reason it was missing?
  364.                 break;
  365.             }
  366. #endif
  367.             
  368.         default:
  369.             Inherited::DoMenuCommand(aCommandNumber);
  370.             break;
  371.     }
  372. } // TApplication::DoMenuCommand 
  373.  
  374. •••••••••••••••••••
  375. In ObjectHeap.cp 
  376.  
  377. •••I added the pragma segment because this entire file wasn't segmentized.
  378.  
  379. //========================================================================================
  380. // CLASS ChunkyBlock
  381. //========================================================================================
  382. #pragma segment Main
  383.  
  384. //----------------------------------------------------------------------------------------
  385. // ChunkyBlock::ChunkyBlock
  386. //----------------------------------------------------------------------------------------
  387.